<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('按下载量统计')" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="role-form">
					<div class="select-list">
						<ul>
							<li>
								<label>用户名：</label>
								<select id="loginName"  name="loginName">
								</select>
							</li>
							<li>
								<label>产品名：</label>
								<input type="text" name="productName"/>
							</li>
							<li>
								<label>单位名：</label>
								<input type="text" name="deptName"/>
							</li>
							<li class="select-time">
								<label>下载时间： </label>
								<input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
								<span>-</span>
								<input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
							</li>
						<!--	<li>
								下载统计：<select name="status" th:with="type=${@dict.getType('business_download_statistics')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
								</select>
							</li>-->
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
		
			<!--<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.removeAll()" shiro:hasPermission="system:role:remove">
		            <i class="fa fa-remove"></i> 打印图片
		        </a>
		        <a class="btn btn-primary single disabled" onclick="$.table.exportExcel()" shiro:hasPermission="system:role:export">
		            <i class="fa fa-download"></i> 导出raster或者vector图片
		        </a>
	        </div>-->
	        
	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table"></table>
			</div>
			<div style="margin-top: 41%;
    				width: 100%;
					height: 100px;
				">
				<text id="zs"></text>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<text id="zssize"></text>
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		var prefix = ctx + "statistics";
		var prefixs = ctx + "system/user";
		$('#startTime').val(getPreviousDay())
		$('#endTime').val(getNextDay())
		$.post(prefixs+"/longinname",function (data){
			var html = "\"<option value=''>--请选择--</option>\""
			for (let i = 0; i <data.data.length; i++) {
				if(data.data[i].loginName != "admin"){
					html += "<option value='"+data.data[i].loginName+"'>"+data.data[i].loginName+"</option>"
				}
			}
			$("#loginName").html(html)
		})
		$.post(prefix+"/selectDownloadStatisticsListzs",function (data){
			console.log(data)
			$("#zs").text("总数："+data.data.zh)
			$("#zssize").text("总数："+data.data.zhsize
			)
		})
		$(function() {
		    var options = {
		        url: prefix + "/selectDownloadStatisticsList",
		        removeUrl: prefix + "/remove",
		        exportUrl: prefix + "/export",
		        modalName: "下载统计",
				//queryParams: queryParams,
		        columns: [
		        {
		            field: 'id',
		            title: ''
		        },
		        {
		            field: 'productName',
		            title: '产品名称',
		            sortable: true
		        },
				{
					field: 'downValue',
					title: '下载量',
					sortable: true
				}]
		    };
		    $.table.init(options);
		});

/*		function queryParams(params) {
			var search = $.table.queryParams(params);
			$('#startTime').val(getPreviousDay())
			$('#endTime').val(getNextDay())
			search.startTime = $.common.join(getPreviousDay());
			search.endTime = $.common.join(getNextDay());
			return search;
		}*/
		//前一天时间
		function getPreviousDay() {
			const today = new Date(); // 获取当前时间
			const previousDay = new Date(today); // 复制当前时间对象
			previousDay.setDate(today.getDate()); // 将日期减少一天
			return formatDate(previousDay);
		}
		//后一天时间
		function getNextDay() {
			const today = new Date(); // 获取当前时间
			const nextDay = new Date(today); // 复制当前时间对象
			nextDay.setDate(today.getDate() + 1); // 将日期增加一天
			return formatDate(nextDay);
		}
		//时间格式转换
		function formatDate(date) {
			const year = date.getFullYear();
			const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始，需要加1，并且补零
			const day = String(date.getDate()).padStart(2, '0'); // 日期可能是一位数，需要补零
			return `${year}-${month}-${day}`;
		}

	</script>
</body>
</html>